package perl.lexical.classes;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Operator extends TokenClass{
	
	public final static String PLUS = "+";
	public final static String MINUS = "-"; 
	public final static String MULTIPLY = "*"; 
	public final static String DIVIDE = "/"; 
	public final static String EQUAL = "=="; 
	public final static String NOTEQUAL = "!=";
	public final static String ASSIGN = "="; 
	public final static String GREATER = ">"; 
	public final static String LESS = "<"; 
	public final static String GRorEQ = "=>"; 
	public final static String LESSorEQ = "<="; 
	public final static String INCREASE = "++"; 
	public final static String DECREASE = "--";
	
	public final static String[] operators = {MULTIPLY, DIVIDE, PLUS, MINUS, DECREASE, INCREASE,  EQUAL, NOTEQUAL, ASSIGN, GRorEQ, LESSorEQ,  GREATER, LESS};

	
	@Override
	public Token generateToken(String lexem) {
		 Pattern p;
		 Matcher m;

		 for(String operator : operators){
			 
			 p = Pattern.compile("\\s*\\" + operator +"|\\s*\\" + operator +"[\\s*\\w*();\\'\"\\$@].*");
			 m = p.matcher(lexem);
			 
			 
			 if(m.matches()){
				 return new Token(className, operator);
			 }
		 }
		 
		return null;
	}
	

	public Operator(){
		className = TokenClassEnum.OPERATOR;
	}
	
}
